package tv.accedo.memory.dao;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

import tv.accedo.memory.model.Achi;
import tv.accedo.memory.util.HibernateUtil;

public class AchiDao {

	public String getCardsnByAchisn(String achi_sn) {
		String card_sn = null;  
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		
		Query query = session.createQuery("select card_sn from Achi achi where achi.achi_sn = ?")
				.setParameter(0, achi_sn); 
		card_sn = (String) query.uniqueResult(); 
		session.flush();
		session.close();
		return card_sn; 
	}
	
	public List<Achi> getAllAchi() {
		List<Achi> achiList = new ArrayList<Achi>();
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();

		Query query = session
				.createQuery("from Achi achi order by achi.achi_sn asc");
		achiList = query.list();
		session.flush();
		session.close();
		return achiList;
	}
}
